/*
 * Copyright (C) 2015 yixun All Rights Reserved.
 * 
 * ApartmentLayoutDiagram.java
 */
package com.yixun.qfbao.xf.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.yixun.qfbao.model.enums.AreaEnum;
import com.yixun.qfbao.util.StringUtil;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * [文件名称]<br>
 * ApartmentLayoutDiagram.java<br>
 * <br>
 * [文件描述]<br>
 * 户型信息 pojo bean<br>
 * <br>
 * [修改记录]<br>
 * 2015-10-14 15:34:12 创建 陶俊代码生成器<br>
 * 
 * @author 陶俊代码生成器
 * @version 1.00
 */
public class ApartmentLayoutDiagram implements Serializable{
    /**
	 * 序列化UID
	 */
	private static final long serialVersionUID = 1L;

	/**
	 *流水号
	 */
	private Long id;
	/**
	 *所属楼盘
	 */
	private Long premisesId;
	/**
	 *创建时间
	 */
	@JSONField (format="yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	/**
	 *更新时间
	 */
	@JSONField (format="yyyy-MM-dd HH:mm:ss")
	private Date updateTime;
	/**
	 *面积
	 */
	private String area;
	/**
	 *户型
	 */
	private String apartmentLayout;
	
	/**
	 *分销小程序需要使用到的查询条件
	 */
	private String weappApartmentLayout;
	/**
	 *描述
	 */
	private String remark;
	/**
	 *图片地址
	 */
	private String url;

	//////////////////////////////////////////v10打通新增字段/////////////////////////////////////////////
	/**
	 * 朝向
	 */
	private String orientations;

	/**
	 * 均价
	 */
	private String averagePrice;

	/**
	 * 户型
	 */
	private String huxingName;

	/**
	 * 结构
	 */
	private String houseStruct;

	/**
	 * 装修情况
	 */
	private String decoration;

	/**
	 * 户型详情
	 */
	private String[] aprtmentInfo;

	/**
	 * 是否删除 0-否，1是
	 */
	private String delFlag;
	
	private List<BigDecimal> totalPrice;

	//////////////////////////////////////////v10打通新增字段/////////////////////////////////////////////


	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}

	/**
	 *设置 :流水号
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**	 
	 *获取 :流水号
	 */
	public Long getId() {
		return this.id;
	}

	/**	 
	 *设置 :所属楼盘
	 */
	public void setPremisesId(Long premisesId) {
		this.premisesId = premisesId;
	}

	/**	 
	 *获取 :所属楼盘
	 */
	public Long getPremisesId() {
		return this.premisesId;
	}

	/**	 
	 *设置 :创建时间
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**	 
	 *获取 :创建时间
	 */
	public Date getCreateTime() {
		return this.createTime;
	}

	/**	 
	 *设置 :更新时间
	 */
	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	/**	 
	 *获取 :更新时间
	 */
	public Date getUpdateTime() {
		return this.updateTime;
	}

	/**	 
	 *设置 :面积
	 */
	public void setArea(String area) {
		this.area = area;
	}

	/**	 
	 *获取 :面积
	 */
	public String getArea() {
		return this.area;
	}

	/**	 
	 *设置 :户型
	 */
	public void setApartmentLayout(String apartmentLayout) {
		this.apartmentLayout = apartmentLayout;
	}

	/**	 
	 *获取 :户型
	 */
	public String getApartmentLayout() {
		return this.apartmentLayout;
	}

	/**	 
	 *设置 :描述
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**	 
	 *获取 :描述
	 */
	public String getRemark() {
		return this.remark;
	}

	/**	 
	 *设置 :图片地址
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	/**	 
	 *获取 :图片地址
	 */
	public String getUrl() {
		return this.url;
	}

	public String getOrientations() {
		return orientations;
	}

	public void setOrientations(String orientations) {
		this.orientations = orientations;
	}

	public String getAveragePrice() {
		return averagePrice;
	}

	public void setAveragePrice(String averagePrice) {
		this.averagePrice = averagePrice;
	}

	public String getHuxingName() {
		return huxingName;
	}

	public void setHuxingName(String huxingName) {
		this.huxingName = huxingName;
	}

	public String getHouseStruct() {
		return houseStruct;
	}

	public void setHouseStruct(String houseStruct) {
		this.houseStruct = houseStruct;
	}

	public String getDecoration() {
		return decoration;
	}

	public void setDecoration(String decoration) {
		this.decoration = decoration;
	}

	public String[] getAprtmentInfo() {
		return aprtmentInfo;
	}

	public void setAprtmentInfo(String[] aprtmentInfo) {
		this.aprtmentInfo = aprtmentInfo;
	}
	
	/**
	 * 根据面积和单价范围设置
	 */
	private void setTotalPrice() {
		List<BigDecimal> areaRange = StringUtil.getMinOrMaxFromSeprateString(
    			this.area, ",", 3);
		List<BigDecimal> priceRange = StringUtil.getMinOrMaxFromSeprateString(
    			this.averagePrice, ",", 3);
		if(areaRange != null && priceRange != null) {
			List<BigDecimal> totalPriceRange = new ArrayList<>();
			totalPriceRange.add(areaRange.get(0).multiply(priceRange.get(0)).
					divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
			totalPriceRange.add(areaRange.get(1).multiply(priceRange.get(1)).
					divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
			this.totalPrice = totalPriceRange;
		}
	}
	
	/**
	 * 判断最低价和最高价是否在范围内
	 * @param minPrice 最低价格
	 * @param maxPrice 最高价格
	 * @return
	 */
	public boolean judgeTotalPriceInRange(int minPrice, int maxPrice) {
		this.setTotalPrice();
		if(totalPrice == null) {
			return false;
		}
		
		if(maxPrice == minPrice) {
			if((maxPrice < this.totalPrice.get(0).longValue()) || (minPrice > this.totalPrice.get(1).longValue())) {
				return false;
			}
		}else if((maxPrice <= this.totalPrice.get(0).longValue()) || (minPrice > this.totalPrice.get(1).longValue())) {
			return false;
		}
		return true;
	}
	
	/**
	 * 判断面积是否在范围内
	 * @param minArea
	 * @param maxArea
	 * @return
	 */
	public boolean judgeAreaInRange(int minArea, int maxArea) {
		List<BigDecimal> areaRange = StringUtil.getMinOrMaxFromSeprateString(
    			this.area, ",", 3);
		if(areaRange != null) {
			if(minArea == maxArea) {
				if((minArea > areaRange.get(1).longValue()) || (maxArea < areaRange.get(0).longValue())) {
					return false;
				}
			}else if((minArea > areaRange.get(1).longValue()) || (maxArea <= areaRange.get(0).longValue())) {
				return false;
			}
			return true;
		}
		return false;
	}
	
	/**
	 * 判断传入的枚举对应的面积是否在范围内
	 * 	只要有一个枚举在传入的范围内，则返回true
	 * @param areaEnumNumbers
	 * @return
	 */
	public boolean judgeAreaInRange(List<Integer> areaEnumNumbers) {
		if(areaEnumNumbers == null || areaEnumNumbers.size() == 0) {
			return true;
		}
		for (Integer areaEnumNo : areaEnumNumbers) {
			int[] minAndMaxValue = AreaEnum.getMinAndMaxValueByNumber(areaEnumNo);
			if(minAndMaxValue != null && this.judgeAreaInRange(minAndMaxValue[0], minAndMaxValue[1])) {
				return true;
			}
		}
		return false;
	}

	public String getWeappApartmentLayout() {
		return weappApartmentLayout;
	}

	public void setWeappApartmentLayout(String weapp_apartmentLayout) {
		this.weappApartmentLayout = weapp_apartmentLayout;
	}
	
	
}
